﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PingPongMain
{
    public static class PrepareField
    {
        public static int WorldRows = Console.WindowHeight;
        public static int WorldCols = Console.WindowWidth;

        private enum Colors
        {
            Red = ConsoleColor.Red,
            Green = ConsoleColor.Green,
            Blue = ConsoleColor.Blue,
            White = ConsoleColor.White,
            DarkGreen = ConsoleColor.DarkGreen,
            Yellow = ConsoleColor.Yellow
        };

        static public void SetGameField()
        {
            Console.ForegroundColor = (ConsoleColor)Colors.Yellow;
            Console.BackgroundColor = (ConsoleColor)Colors.DarkGreen;
            Console.BufferHeight = WorldRows;
            Console.BufferWidth = WorldCols;
            for (int i = 0; i < PrepareField.WorldCols; i++)
            {

                Console.SetCursorPosition(i, PrepareField.WorldRows - 3);
                Console.Write("_");
            }
        }
        static public int StartingScreen()
        {
            Score.ClearScore();
            Score.Lives = 3;
            Score.PlayerScore = 0;

            Console.SetCursorPosition(PrepareField.WorldCols / 2 - 10, PrepareField.WorldRows / 2);
            Console.WriteLine("Move your paddle with Up and Down arrows");

            Console.SetCursorPosition(PrepareField.WorldCols / 2 - 10, PrepareField.WorldRows / 2 + 1);
            Console.WriteLine("Press Spacebar for pause");

            Console.SetCursorPosition(PrepareField.WorldCols / 2 - 10, PrepareField.WorldRows / 2 + 2);
            Console.WriteLine("Choose difficulty from 1 to 5");
            int number;
            string read;
            
            try
            {
                read = Console.ReadLine();
                int difficulty = int.Parse(read);
                CheckInput(difficulty, 1, 5);
                return difficulty;
            }
            catch (ExceptionHandler)
            {
                do
                {
                    Console.WriteLine("Choose difficulty from 1 to 5");
                    read = Console.ReadLine();
                   

                }
                while (!int.TryParse(read, out number) || (int.Parse(read) < 1 || (int.Parse(read) > 5)));

                int difficulty = int.Parse(read);
                return difficulty;
            }
            catch (Exception)
            {
                do
                {
                    Console.WriteLine("Choose difficulty from 1 to 5");
                    read = Console.ReadLine();


                }
                while (!int.TryParse(read, out number) || (int.Parse(read) < 1 || (int.Parse(read) > 5)));

                int difficulty = int.Parse(read);
                return difficulty;
            }
        }
        public static void CheckInput(int input, int startRange, int endRange)
        {

            if (input <startRange || input > endRange)
                throw new ExceptionHandler(startRange, endRange);
        }
    }
}
